vLast_Counterspell_Anyone_Check = 0.1
function ccR_Mage_CounterspellAnyone(specNumber)
	if specNumber == nil then specNumber = ccrSpec() end
	local vUseAbility = ccRS["Mage_" .. specNumber .. "_UseCounterspellAnyone"]
	if vUseAbility
	and ccrPlayerHasSpell(COUNTERSPELL)
	and ccrSpellIsReady(COUNTERSPELL)
	and (GetTime()-vLast_Counterspell_Anyone_Check) > 0.25
	then
		local x
		if # tblPGetNearbyEnemies > 0 then
			for x = 0, # tblPGetNearbyEnemies do
				local obj = tblPGetNearbyEnemies[x]
				if obj
				and obj:Exists()
				and (obj:GetTarget():Exists() and obj:GetTarget():GetName() == ccrPlayerName())
				and obj:InLineOfSight()
				and ccrUnitIsCastingOrChanneling(obj)
				and Player:IsFacing(obj)
				and ccrSpellCanAttack(COUNTERSPELL, obj)
				then
					local vCounterSpell = GetSpellInfo(COUNTERSPELL)
					if ccrUnitIsCasting(obj)
					and ccrUnitHasLeftOnCast(obj, 1)
					then
						if ccrPlayerIsCastingOrChanneling() then SpellStopCasting() end
						obj:CastSpellByName(vCounterSpell)
						return
					end
					if ccrUnitIsChanneling(obj) then
						if ccrPlayerIsCastingOrChanneling() then SpellStopCasting() end						
						obj:CastSpellByName(vCounterSpell)
						return
					end									
				end
			end
		end	
		vLast_Counterspell_Anyone_Check = GetTime()
	end
end
